<template>
	<view class="msg_notice bg-fff">
		<u-sticky bgColor="#fff" class="u-border-bottom py-10 shadow-s">
			<view class="flex-around-center py-20">
				<view class="fs-28 py-6 px-16 rd-50" :class="cateid == item.id?'bg-primary c-fff':''" v-for="(item,index) in category" :key="index"  @click="changecate(item)">
					{{item.name}}
				</view>
			</view>
		</u-sticky>
		<view class="no_html" v-if="list.length==0">
			<image src="@/static/images/no_img3.png" mode=""></image>
			<text>暂无列表</text>
		</view>
		<view v-else>			
			<u-cell :title="item.title" :isLink="true"  v-for="(item,index) in list" :key="index" @click="goDetails(item.id)"></u-cell>
			<view class="mall_loading" v-if="list.length">
				<u-loadmore :status="status" color='#999' />
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				status: 'loadmore',//加载前值为loadmore，加载中为loading，没有数据为nomore
				page:1,
				type: '',
				list:[],
				category:[],
				cateid:0,
			};
		},
		onLoad(options) {
			this.type = options.m_type;
			
			if(options.m_type == 2) {
				uni.setNavigationBarTitle({
					title: '重要通知'
				})
			}
			
			if(options.m_type == 3) {
				uni.setNavigationBarTitle({
					title: '推广必读'
				})
				
			}
			
		},
		onShow() {
			this.page=1
			this.getCategory();
		},
		methods:{
			getCategory(){
				if(this.type==3){
					this.$httpApi.msgsnedCate().then((res)=>{
						if(res.code==1){
							this.category = res.data.cate_data;
							this.cateid = this.category[0].id;
							this.getList();
						}
					})
				}
			},
			changecate(item){
				console.log("分类点击：：",item.id);
				this.cateid = item.id;
				this.page=1;
				this.getList();
			},
			goDetails(id) {
				// uni.navigateTo({
				// 	url:'/pages/order/text-details?ids=' + id
				// })
			},
			// 列表
			getList(){
				var that = this
				var params = {
					page:that.page,
					cate_id:that.cateid,
				}
				that.$httpApi.msgsnedList(params).then((res)=>{
					if(res.code==1){
						if(that.page==1){
							that.list=[]
						}
						if (res.data.data.length<1) {
							that.status = 'nomore';
						} else {
							that.status = 'loadmore'
						}
						that.list=that.list.concat(res.data.data)
					}
				})
			},
		},
		onReachBottom(){
			 if(this.status == 'nomore' || this.status == 'loading'){
			 	return
			 }
			 this.page++
			 this.getList()
		},
		// 右上角点击事件
		onNavigationBarButtonTap(){
			var that = this
			that.$tips.showLoading('加载中')
			that.$httpApi.userMsgSave().then((res)=>{
				that.$tips.hideLoading()
				if(res.code==1){
					that.list.forEach(item=>{
						item.status=2
					})
				}
			})
		},
	}
</script>

<style lang="less">
	.msg_notice{
		width: 100%;
		box-sizing: border-box;
	}
	.u-tabs__wrapper__nav{min-width: 100%!important;}
</style>
